let t = require;
let e = module;
let o = e.exports;
o.default = e.exports;

('use strict');
console.log('start');
var _n163,
  i =
    (this && this.__extends) ||
    ((_n163 = function n(t, e) {
      return (_n163 =
        Object.setPrototypeOf ||
        ({
          __proto__: []
        } instanceof Array &&
          function (t, e) {
            t.__proto__ = e;
          }) ||
        function (t, e) {
          for (var o in e) {
            Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
          }
        })(t, e);
    }),
      function (t, e) {
        function o() {
          this.constructor = t;
        }
        _n163(t, e),
          (t.prototype =
            null === e
              ? Object.create(e)
              : ((o.prototype = e.prototype), new o()));
      });
Object.defineProperty(o, '__esModule', {
  value: !0
}),
  (o.StoreItemCom2 = void 0);
var r = t('UIComponent'),
  a = t('StoreMrg'),
  s = t('UIMrg'),
  c = t('GainPanel'),
  l = t('AbsInfo'),
  u = t('ResMrg'),
  h = t('ItemCfg'),
  p = t('ComUtils'),
  f = t('SoundMrg'),
  d = t('TimeMrg'),
  g = t('GameSDK'),
  _ = t('DateTimeUtils'),
  y = t('BattleUtils'),
  C = t('CivilizationMrg'),
  m = t('BagMrg'),
  v = t('GeneralTips'),
  b = t('UmaSdkHelper'),
  M = t('MathUtils'),
  I = t('StoreItemColors'),
  A = t('LangCfg'),
  w = (function (t) {
    function e() {
      return (null !== t && t.apply(this, arguments)) || this;
    }
    return (
      i(e, t),
      (e.prototype.onInit = function () {
        t.prototype.onInit.call(this),
          (this._imgBg = this.view.getComponent(cc.Sprite)),
          (this._txtName = p.default.getComponent(
            cc.Label,
            this.view,
            'txtName'
          )),
          (this._imgIcon = p.default.getComponent(
            cc.Sprite,
            this.view,
            'imgIcon'
          )),
          (this._txtTime = p.default.getComponent(
            cc.Label,
            this.view,
            'txtTime'
          )),
          (this._txtDesc = p.default.getComponent(
            cc.Label,
            this.view,
            'txtDesc'
          )),
          (this._btnAd = p.default.getComponent(cc.Button, this.view, 'btnAd')),
          this._btnAd.node.on(
            cc.Node.EventType.TOUCH_END,
            this.onTouchAdHandler,
            this
          ),
          (this._btnBuy = p.default.getComponent(
            cc.Button,
            this.view,
            'btnBuy'
          )),
          this._btnBuy.node.on(
            cc.Node.EventType.TOUCH_END,
            this.onTouchBuyHandler,
            this
          ),
          (this._btnFree = p.default.getComponent(
            cc.Button,
            this.view,
            'btnFree'
          )),
          this._btnFree.node.on(
            cc.Node.EventType.TOUCH_END,
            this.onTouchFreeHandler,
            this
          ),
          (this._imgPriceIcon = p.default.getComponent(
            cc.Sprite,
            this._btnBuy.node,
            'Background/imgPrice/imgIcon'
          )),
          (this._txtPrice = p.default.getComponent(
            cc.Label,
            this._btnBuy.node,
            'Background/imgPrice/txtValue'
          )),
          (this.view.active = !0);
      }),
      (e.prototype.onLang = function () {
        (p.default.getComponent(
          cc.Label,
          this.view,
          'btnFree/Background/txtLabel'
        ).string = A.LangCfg.ins.getContent(200305)),
          (this._upTitle = A.LangCfg.ins.getContent(200307)),
          this.info &&
          ((this._txtName.string = A.LangCfg.ins.getContent(this._info.name)),
            (this._txtDesc.string = A.LangCfg.ins.getContent(this._info.desc)));
      }),
      (e.prototype.onUpdate = function (e) {
        t.prototype.onUpdate.call(this, e)
        if (this.info && this.info.count < 1) {
          var o = this.info.time - d.TimeMrg.serverTime;
          this._txtTime.string = this._upTitle + _.DateTimeUtils.formatCountdown(o, 3);
          if (o < 0 && !this._btnAd.interactable) {
            this._btnAd.interactable = !0;
            p.default.setGray(this._btnAd.node, !1);
          } else {
            if (o > 0 && !this._isBtnAdGray) {
              this._btnAd.interactable = !1;
              p.default.setGray(this._btnAd.node, !0)
            }
          }

        }
      }),
      (e.prototype.onTouchFreeHandler = function () {
        f.SoundMrg.click(),
          this.buy(),
          b.default.storeBuyBox(this.info.kind, b.UmaSdkGainType.Free);
      }),
      (e.prototype.onTouchAdHandler = function () {
        f.SoundMrg.click(),
          d.TimeMrg.serverTime >= this._info.time &&
          (b.default.storeBuyBox(this.info.kind, b.UmaSdkGainType.AdVideo),
            g.default.videoAdBuy(
              this.info.id,
              A.LangCfg.ins.getContent(this.info.name),
              this.buyBuyAd,
              this
            ));
      }),
      (e.prototype.onTouchBuyHandler = function () {
        switch ((f.SoundMrg.click(), this.info.priceType)) {
          case 1:
            m.BagMrg.ins.getCount(m.BagMrg.GOLD) >= this.info.price
              ? this.buy()
              : v.GeneralTips.notEnoughGold();
            break;

          case 2:
            m.BagMrg.ins.getCount(m.BagMrg.DIAMOND) >= this.info.price
              ? (this.buy(),
                b.default.storeBuyBox(this.info.kind, b.UmaSdkGainType.Diamond))
              : v.GeneralTips.notEnoughDiamond();
        }
      }),
      (e.prototype.buy = function () {
        a.StoreMrg.ins.buy(this.info), this.aaa();
      }),
      (e.prototype.buyBuyAd = function () {
        a.StoreMrg.ins.buyBuyAd(this.info), this.aaa();
      }),
      (e.prototype.aaa = function () {
        for (
          var t = y.default.lotteryBoxItems(
            this.info.kind,
            C.CivilizationMrg.ins.id
          ),
          e = [],
          o = 0;
          o < t.length;
          o++
        ) {
          e.push([t[o].id, t[o].count]);
        }
        s.UIMrg.show(c.GainPanel, e);
      }),
      Object.defineProperty(e.prototype, 'info', {
        get: function get() {
          return this._info;
        },
        set: function set(t) {
          this._info != t &&
            (this._info && this._info.targetOff(this),
              t && t.on(l.InfoEvent.Changed, this.onChangedHandler, this),
              (this._info = t),
              t &&
              (u.ResMrg.loadSpriteByAtlas(
                this._imgBg,
                'Atlas/General',
                this._info.background
              ),
                this.setOutLineColor(this._info.background)),
              this.refresh());
        },
        enumerable: !1,
        configurable: !0
      }),
      (e.prototype.setOutLineColor = function (t) {
        var e = M.default.convertColor(I.StoreItemOutLineColors[t]),
          o = p.default.getComponent(cc.LabelOutline, this.view, 'txtName');
        (o.color = e),
          ((o = p.default.getComponent(
            cc.LabelOutline,
            this.view,
            'txtDesc'
          )).color = e),
          ((o = p.default.getComponent(
            cc.LabelOutline,
            this.view,
            'txtTime'
          )).color = e);
      }),
      (e.prototype.onChangedHandler = function () {
        this.refresh();
      }),
      (e.prototype.refresh = function () {
        if (!this._info) return;
        (this._txtName.string = A.LangCfg.ins.getContent(this._info.name));
        (this._txtDesc.string = A.LangCfg.ins.getContent(this._info.desc));
        (this._txtPrice.string = this.info.price.toString());
        (this._isBtnAdGray = d.TimeMrg.serverTime < this.info.time);
        (this._btnAd.interactable = d.TimeMrg.serverTime >= this.info.time);
        p.default.setGray(this._btnAd.node, !this._btnAd.interactable);

        if (this.info.count > 0) {
          (this._btnFree.node.active = !0);
          (this._btnAd.node.active = !1);
          (this._btnBuy.node.active = !1);
          (this._txtTime.node.active = !1);
        } else {
          (this._btnFree.node.active = !1);
          (this._btnAd.node.active = !0);
          (this._btnBuy.node.active = !0);
          (this._txtTime.node.active = !0);
        }

        this.loadIcon();
      }),
      (e.prototype.loadIcon = function () {
        if (this._info.icon)
          u.ResMrg.loadSpriteByAtlas(
            this._imgIcon,
            'Atlas/Store',
            this._info.icon
          );
        else {
          var t = h.ItemCfg.ins.getData(this._info.itemId);
          u.ResMrg.loadSpriteByAtlas(this._imgIcon, 'Atlas/Item', t.icon);
        }
        this._info.priceType < 3 &&
          (t = h.ItemCfg.ins.getData(this._info.priceType)) &&
          u.ResMrg.loadSpriteByAtlas(this._imgPriceIcon, 'Atlas/Item', t.icon);
      }),
      e
    );
  })(r.UIComponent);
(o.StoreItemCom2 = w), console.log('end');
module.exports = e.exports;
